//
//  IMINetConnection.h
//  IMINet
//
//  Created by Travis on 09-11-13.
//  Copyright 2009 Exmart. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "IMINetRequest.h"
#import "IMINetResponse.h"
#import <IMIBase/IMIBaseEvent.h>

#pragma mark Events  - IMINetConnection
#pragma mark -

#define IMINetConnectionEventSuccess	@"IMINetConnectionEventSuccess"
#define	IMINetConnectionEventFail	@"IMINetConnectionEventFail"
#define	IMINetConnectionEventLoading	@"IMINetConnectionEventLoading"
#define	IMINetConnectionEventFinish	@"IMINetConnectionEventFinish"
#define	IMINetConnectionEventBegin	@"IMINetConnectionEventBegin"

#pragma mark -

@class IMINetConnection,IMINetConnectionManager;

@protocol IMINetConnectionDelegate
@optional
-(void)connection:(IMINetConnection *)connection successWithContentLength:(NSInteger)clength;
-(void)connection:(IMINetConnection *)connection failWithString:(NSString*)s;
-(void)connectionDidReceiveData:(IMINetConnection *)connection;
-(void)connectionDidFinishLoading:(IMINetConnection *)connection;

@end



@interface IMINetConnection : NSURLConnection {
	NSMutableData *data;                   // accumulated data received on this connection
    NSString *uuid,*username,*password;
	IMINetRequest *request;
	IMINetResponse *response;
	
	
	IMINetConnectionManager *manager;
	NSObject<IMINetConnectionDelegate> *target;
	
	NSUInteger contentLength;
}

@property (nonatomic,retain) NSString *uuid;
@property (nonatomic,retain) NSString *username;
@property (nonatomic,retain) NSString *password;


@property (nonatomic,readonly) NSUInteger totalBytes;
@property (nonatomic,readonly) NSUInteger loadedBytes;


@property (nonatomic,retain) IMINetRequest *request;
@property (nonatomic,retain) IMINetResponse *response;
@property (nonatomic,assign) IMINetConnectionManager *manager;

- (id) initWithRequest:(IMINetRequest *)req;

@end



